All Questions
18 questions
0votes
1answer
88views
Bash create parameter named array within function
I'm attempting to write a function that writes arrays with a name that's passed in. Given the following bash function: function writeToArray { local name="$1" echo "$name" ...
-1votes
1answer
471views
Redirect a part of mapfile function to stdout but not into the array
Summary: Like we have Stdout Stderr, I would like to create Stdstatus. Stdout can be stored in array and Stdstatus can be printed for user. I didn't know that stderr could be used for other messages ...
1vote
1answer
142views
appending values in a dynamic array
#!/bin/bash range=$(seq -f "cen%04g" 1052 1099) range1=$(seq -f "rh%04g" 1052 1099) check () { for node1 in ${range};do ping -q -c 1 -w 3 -s 10 $node1 >/dev/null if [ ...
1vote
2answers
1kviews
Got bad array subscript when wring a function printing the fibonacci numbers
This is my code to write a function which prints the Fibonacci numbers function fib { fib_array=( 0 1 ) count=3 while [[ $count -le $1 ]] do fib_new=$...
0votes
1answer
216views
Awk function, syntax error near unexpected 'myArr,'
I am not sure why my simple function causes "Syntax error near unexpected 'myArr,'. I taking an array, lookup key value and a line item section name as arguments. Each row in the array is "," ...
8votes
2answers
4kviews
What's the idiomatic way of returning an array in a zsh function?
I have this function, rpargs () { local i args=() for i in "$@" do test -e "$i" && args+="$(realpath --canonicalize-existing -- "$i")" || args+="$i" done } And I ...
3votes
3answers
5kviews
Generic function to loop over inputs and execute a command in bash?
I was trying to create a function that loops over inputs and executes a command - regardless of how they are delimited. function loop { # Args # 1: Command # 2: Inputs for ...
3votes
2answers
389views
Add to array only within scope of function
I'm writing a function that will make a REST API calls which could be either GET, PUT, DELETE, POST, etc. I would like to feed this method to the function as a parameter and add it to the options ...
0votes
1answer
357views
Shell Function: Sequence of Pipelines as Argument
I have a shell function (in .bashrc) which creates a temp file, executes the arguments (including all sequence of pipelines), redirects it to a temp file and then open it in VS Code. I invoke the ...
2votes
3answers
4kviews
bash array with space in element [closed]
I have a text log file $ cat aaa 673 20160405 root "/path_to/gis/20160401/20160301_placement_map_org.dbf" "" 673 20160405 root "/path_to/gis/20160401/...
2votes
1answer
265views
Detect optional function argument (array)
Consider this function: function add_one(in_ar, each) { for (each in in_ar) { in_ar[each]++ } } I would like to modify it such that if a second array is provided, it would be used instead ...
4votes
2answers
1kviews
Zsh, Indirect array variable assignment without using eval
I have a variable VARNAME which contains a name of another variable. I'd like to assign to this another variable without using eval. How can I do that? Th reason I don't want to use eval is the ...
2votes
2answers
3kviews
Function to iterate over array
I am using the following script, so as to call a function that is supposed to iterate over an array. #!/bin/bash function iterarr { for item in "$1" do echo "$item" done } myarr=...
1vote
1answer
731views
How to split Bash array into arguments
I wrote a bash script for listing python processes, ram usage and PID and status in human readable form with colored lines. But I have some trouble with working time of the script. Because of the ...
0votes
1answer
103views
display array in a function - not working
What am I missing here? I have created a simple array: declare -a appArray=( "item1 -a -b" "item2 -c -d" ) If I echo this I can see it all echo ${appArray[@]} > item1 -a -b item2 -c ...